/*=============================================================================
**                                  
**                      Proprietary - Copyright (C) 2013
**-----------------------------------------------------------------------------
** Supported MCUs      : <STM32F103 / MCU independent>
** Supported Compilers : <KeilC ARM / compiler independent>
**-----------------------------------------------------------------------------
** File name         : Seg7Disp.c
**
** Module name       : Seg7Disp
**
**
** Summary: __________________________
**
**= History ====================================================================
** 1.0 31/03/2013  VietComp
** - Creation
==============================================================================*/

/******************************************************************************/
/* INCLUSIONS                                                                 */
/******************************************************************************/
#include <Seg7Disp.h>

/*****************************************************************************/
/* DEFINITION OF TYPES                                                       */
/*****************************************************************************/
typedef struct {
	void  (*LEDSelectFunc)(uint8);
	void  (*LEDOutDataFunc)(uint8);
	void  (*DisableAllLed)(void);
}Seg7Disp_InitTypedef;
/******************************************************************************/
/* DECLARATION OF VARIABLES OF MODULE                                         */
/* Declaration of local variables shall have the specifier STATIC             */
/******************************************************************************/
static Seg7Disp_InitTypedef dv;
static uint8 LEDPanel[SEG7DISP_LED_NBR] = {0};
static uint8* LEDTable;
static uint8 ScanningLED = 0;
/*****************************************************************************/
/* DECLARATION OF LOCAL FUNCTIONS (Internal Functions)                       */
/* Declaration of local functions shall have the specifier STATIC            */
/*****************************************************************************/

/*****************************************************************************/
/* DEFINITION OF GLOBAL FUNCTIONS (APIs, Callbacks and MainFunction(s))      */
/*****************************************************************************/

/******************************************************************************
** Function name: Seg7Disp_Init( const uint8* LEDTable, 
**                               const void* LEDSelectFunc,
**                               const void* LEDOutDataFunc)
** Description: The function import data to LED
** Parameter X : 
** Return value: Reference Seg7Disp_ReturnTypeDef type
** Remarks: global variables used, side effects
******************************************************************************/
void Seg7Disp_Init( uint8* iLEDTable, 
                    void* iLEDSelectFunc,
                     void* iLEDOutDataFunc,
					           void* iDisableAllLed)
{
  if(iLEDTable == NULL_PTR || iLEDSelectFunc == NULL_PTR || iLEDOutDataFunc == NULL_PTR || iDisableAllLed == NULL_PTR)
	{
		/* do nothing */
	}
	else
	{
		LEDTable = iLEDTable;
		dv.LEDSelectFunc = (void (*) (uint8))iLEDSelectFunc;
		dv.LEDOutDataFunc = (void (*) (uint8))iLEDOutDataFunc;
		dv.DisableAllLed = (void (*) (void))iDisableAllLed;
	}
}	
/******************************************************************************
** Function name: Seg7Disp_DisplayLocation( const uint8* dat, 
**                                         const uint8* add)
** Description: The function import data to LED
** Parameter X : dat - data display
**               add - location of led
** Return value: Reference Seg7Disp_ReturnTypeDef type
** Remarks: global variables used, side effects
******************************************************************************/
Seg7Disp_ReturnTypeDef Seg7Disp_DisplayLocation( uint8 dat, 
                                                 uint8 add)
{
	Seg7Disp_ReturnTypeDef returnValue;
	/* check valid of led */
	if(add > SEG7DISP_LED_NBR || dat >9)
	{
    LEDPanel[add] = 0xff;
		returnValue = SEG7DISP_DISPLAY_OUTOFRANGE;
	}
	else 
	{
		LEDPanel[add] = LEDTable[dat];
		returnValue = SEG7DISP_DISPLAY_SUCCESS;
	}
	return returnValue;
}
/*****************************************************************************/
/* DEFINITION OF LOCAL FUNCTIONS (Internal Functions)                        */
/* Declaration of local functions shall have the specifier STATIC            */
/*****************************************************************************/
/******************************************************************************
** Function name: Seg7Disp_DisplayRefresh(void)
** Description: The function refresh led data
** Parameter X : None
** Return value: Reference Seg7Disp_ReturnTypeDef type
** Remarks: global variables used, side effects
******************************************************************************/
void Seg7Disp_DisplayRefresh(void)
{
	/* looping scan led */
	if(ScanningLED<SEG7DISP_LED_NBR)
	{
		/* disable all led */
		dv.DisableAllLed();
		/* select location led */
		dv.LEDSelectFunc(ScanningLED);
		/* out data to LED */
		dv.LEDOutDataFunc(LEDPanel[ScanningLED]);
		ScanningLED++;
	}
	else
	{
		/* reset location scan */
		ScanningLED = 0;
	}
}

/************************* End of File ******************************************/


